/* 
请你返回在两个字符串数组中 都恰好出现一次 的字符串的数目。
输入：words1 = ["leetcode","is","amazing","as","is"], words2 = ["amazing","leetcode","is"]

输出：2

*/
var countWords = function(words1, words2) {
  const res1 = [];
  for (let i = 0; i < words1.length; i++) {
    if (words1.indexOf(words1[i]) === words1.lastIndexOf(words1[i])) {
      res1.push(words1[i]);
    }
  }

  const res2 = []
  for (let i = 0; i < words2.length; i++) {
    if (words2.indexOf(words2[i]) === words2.lastIndexOf(words2[i])) {
      res2.push(words2[i]);
    }
  }

  const res = res1.filter(item => new Set(res2).has(item)  )

  return res.length





};
countWords( ["leetcode","is","amazing","as","is"] , ["amazing","leetcode","is"])